package com.two.shopping.service.serviceImpl;

import com.two.shopping.anno.Log;
import com.two.shopping.mapper.ILoginMapper;
import com.two.shopping.pojo.Admin;
import com.two.shopping.pojo.User;
import com.two.shopping.service.ILoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private ILoginMapper loginMapper;


    @Override
    public User userLogin(User user) throws Exception {
        //  user.setCreateTime(LocalDateTime.now());
        // user.setUpdateTime(LocalDateTime.now());
        return loginMapper.userLogin(user);
    }

    @Override
    public Admin adminLogin(Admin admin) throws Exception {
        //  user.setCreateTime(LocalDateTime.now());
        // user.setUpdateTime(LocalDateTime.now());
        return loginMapper.adminLogin(admin);
    }


    @Override
    public User createUser(User user) throws Exception {
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        log.info("{}", user);
        User user1 = loginMapper.selectPhoneNumberOr1(user);
        if (user.getUsername() != null) {
            loginMapper.createUser(user);
            return null;
        } else {
            throw new IllegalArgumentException("注册手机号已存在");

        }

    }
}
